package com.no1.zy.mapper;

import com.no1.zy.pojo.GoodsType;
import com.no1.zy.pojo.GoodsType;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface GoodsTypeMapper {

    @Insert(value = "insert into goods_type(goods_type_id, goods_type_name) "
            + "values(#{goodsTypeId, jdbcType=INTEGER}, "
            + "#{goodsTypeName, jdbcType=VARCHAR})")
    void insertOne(GoodsType goodsType);

    @Update(value = "update goods_type set goods_type_name = #{goodsTypeName, jdbcType=VARCHAR} "
            + "where goods_type_id = #{goodsTypeId, jdbcType=INTEGER}")
    void updateOne(GoodsType goodsType);

    @Delete(value = "delete from goods_type where goods_type_id "
            + "= #{goodsTypeId, jdbcType=INTEGER}")
    void deleteById(Integer goodsTypeId);

    @Select(value = "select * from goods_type where goods_type_id "
            + "= #{goodsTypeId, jdbcType=INTEGER}")
    @Results(value = {
            @Result(column = "goods_type_id", property = "goodsTypeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "goods_type_name", property = "goodsTypeName", jdbcType = JdbcType.VARCHAR)
    })
    GoodsType selectOne(Integer goodsTypeId);

    @Select("select * from goods_type")
    @Results(value = {
            @Result(column = "goods_type_id", property = "goodsTypeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "goods_type_name", property = "goodsTypeName", jdbcType = JdbcType.VARCHAR)
    })
    List<GoodsType> selectAll();
}
